package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbQuestionTitle;
import com.ruoyi.wb.service.IWbQuestionTitleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 问卷标题Controller
 * 
 * @author ruoyi
 * @date 2024-10-19
 */
@Api(tags="维保调查问卷")
@RestController
@RequestMapping("/wb/title")
public class WbQuestionTitleController extends BaseController
{
    @Autowired
    private IWbQuestionTitleService wbQuestionTitleService;

    /**
     * 查询问卷标题列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WbQuestionTitle wbQuestionTitle)
    {
        startPage();
        List<WbQuestionTitle> list = wbQuestionTitleService.selectWbQuestionTitleList(wbQuestionTitle);
        return getDataTable(list);
    }

    /**
     * 导出问卷标题列表
     */
    @Log(title = "问卷标题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbQuestionTitle wbQuestionTitle)
    {
        List<WbQuestionTitle> list = wbQuestionTitleService.selectWbQuestionTitleList(wbQuestionTitle);
        ExcelUtil<WbQuestionTitle> util = new ExcelUtil<WbQuestionTitle>(WbQuestionTitle.class);
        util.exportExcel(response, list, "问卷标题数据");
    }

    /**
     * 获取问卷标题详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wbQuestionTitleService.selectWbQuestionTitleById(id));
    }

    /**
     * 新增问卷标题
     */
    @Log(title = "问卷标题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbQuestionTitle wbQuestionTitle)
    {
        return toAjax(wbQuestionTitleService.insertWbQuestionTitle(wbQuestionTitle));
    }

    /**
     * 修改问卷标题
     */
    @Log(title = "问卷标题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbQuestionTitle wbQuestionTitle)
    {
        return toAjax(wbQuestionTitleService.updateWbQuestionTitle(wbQuestionTitle));
    }

    /**
     * 删除问卷标题
     */
    @Log(title = "问卷标题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wbQuestionTitleService.deleteWbQuestionTitleByIds(ids));
    }
    /**
     * 获取是否维保申请
     */
    @GetMapping(value = "/byUser")
    public AjaxResult byUser()
    {
        return success(wbQuestionTitleService.byUser());
    }
}
